package com.coderman.controller.business;

import com.coderman.business.service.IAdultexamService;
import com.coderman.common.annotation.ControllerEndpoint;
import com.coderman.common.error.SystemException;
import com.coderman.common.model.student.Adultexam;
import com.coderman.common.model.system.Dept;
import com.coderman.common.response.ResponseBean;
import com.coderman.common.vo.system.PageVO;
import com.wuwenze.poi.ExcelKit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报考管理
 *
 * @Author liwei
 * @Date 2023/1/8 14:11
 * @Version 1.0
 **/
@Api(tags = "系统模块-报考相关接口")
@Controller
@RequestMapping("/adultexam")
public class AdultexamController {


    @Autowired
    private IAdultexamService adultexamService;

    /**
     * 报考列表
     *
     * @return
     */
    @ApiOperation(value = "报考列表", notes = "报考列表,根据报考名模糊查询")
    @GetMapping("/findAdultexamList")
    @ResponseBody
    //@RequestParam 的意思https://blog.csdn.net/weixin_43808717/article/details/117219888
    public ResponseBean<PageVO<Adultexam>> findAdultexamList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(value = "pageSize") Integer pageSize,
                                                                 Adultexam Adultexam) {
        PageVO<Adultexam> AdultexamsList = adultexamService.findAdultexamList(pageNum, pageSize, Adultexam);
        return ResponseBean.success(AdultexamsList);
    }

    /**
     * 所有报考
     *
     * @return
     */
    @ApiOperation(value = "所有报考")
    @GetMapping("/findAll")
    @ResponseBody
    public ResponseBean<List<Adultexam>> findAll() {
        List<Adultexam> AdultexamS = adultexamService.findAll();
        return ResponseBean.success(AdultexamS);
    }

//    /**
//     * 查找报考主任
//     *
//     * @return
//     */
//    @ApiOperation(value = "报考主任", notes = "查找报考主任,排除掉已经禁用的用户")
//    @GetMapping("/findDeanList")
//    @ResponseBody
//    public ResponseBean<List<DeanVO>> findDeanList() {
//        List<DeanVO> managerList = adultexamService.findDeanList();
//        return ResponseBean.success(managerList);
//    }

    /**
     * 添加报考
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "添加报考失败", operation = "添加报考")
    @RequiresPermissions({"Adultexam:add"})
    @ApiOperation(value = "添加报考")
    @PostMapping("/add")
    @ResponseBody
    public ResponseBean add(@RequestBody @Validated Adultexam Adultexam) {
        adultexamService.add(Adultexam);
        return ResponseBean.success();
    }

    /**
     * 编辑报考
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "编辑报考")
    @RequiresPermissions({"Adultexam:edit"})
    @GetMapping("/edit/{id}")
    @ResponseBody
    public ResponseBean edit(@PathVariable Integer id) throws SystemException {
        Adultexam Adultexam = adultexamService.edit(id);
        return ResponseBean.success(Adultexam);
    }

    /**
     * 更新报考
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "更新报考失败", operation = "更新报考")
    @ApiOperation(value = "更新报考")
    @RequiresPermissions({"Adultexam:update"})
    @PostMapping("/update")
    @ResponseBody
    public ResponseBean update(@RequestBody @Validated Adultexam Adultexam) throws SystemException {
        adultexamService.update( Adultexam);
        return ResponseBean.success();
    }

    /**
     * 删除报考
     *
     * @param id
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "删除报考失败", operation = "删除报考")
    @ApiOperation(value = "删除报考")
    @RequiresPermissions({"Adultexam:delete"})
    @DeleteMapping("/delete/{id}")
    @ResponseBody
    public ResponseBean delete(@PathVariable Integer id) throws SystemException {
        adultexamService.deleteByPrimaryKey(id);
        return ResponseBean.success();
    }

    /**
     * 导出excel
     * @param response
     */
    @ApiOperation(value = "导出excel", notes = "导出所有报考的excel表格")
    @PostMapping("/excel")
    @RequiresPermissions("Adultexam:export")
    @ControllerEndpoint(exceptionMessage = "导出Excel失败",operation = "导出报考excel")
    public void export(HttpServletResponse response) {
        List<Adultexam> Adultexams = this.adultexamService.findAll();
        ExcelKit.$Export(Dept.class, response).downXlsx(Adultexams, false);
    }

}
